package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.SingerEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 15/10/27.
 * 歌手 gridView 适配器
 * 王锦予
 */
public class Fragment_Man_Singer_GridView_Adapter extends BaseAdapter {
    private List<SingerEntity.ResultEntity.ItemsEntity> data;
    private SingerEntity entity;
    private Context context;
    public Fragment_Man_Singer_GridView_Adapter(Context c, SingerEntity singerEntity){
        context = c;
        entity = singerEntity;
        data = entity.getResult().getItems();

    }
    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            //通过布局加载器来加载行布局文件
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.frangment_man_singer_gridview_item, null);
            //初始化控件
            holder.man_singer_gridView_image = (ImageView) convertView.findViewById(R.id.man_singer_gridView_image);
            holder.manSinger_tv = (TextView) convertView.findViewById(R.id.manSinger_tv);
            //添加标签
           convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        //设置组件
        holder.manSinger_tv.setText(entity.getResult().getItems().get(position).getArtist_name());
        Picasso.with(context).load(entity.getResult().getItems().get(position).getPicture_300_300()).into(holder.man_singer_gridView_image);

        return convertView;
    }
    public class ViewHolder{
        private ImageView man_singer_gridView_image;
        private TextView manSinger_tv;
    }
}
